import sqlite3

conn = sqlite3.connect('instance/app.db')
cursor = conn.cursor()

# 获取数据库统计信息
print("===== 数据库统计信息 =====")
cursor.execute('SELECT COUNT(*) FROM "user"')
print('用户总数:', cursor.fetchone()[0])
cursor.execute('SELECT COUNT(*) FROM skill')
print('技能总数:', cursor.fetchone()[0])
cursor.execute('SELECT COUNT(*) FROM article')
print('文章总数:', cursor.fetchone()[0])

# 获取user表的结构
print("\n===== 用户表结构 =====")
cursor.execute('PRAGMA table_info("user")')
columns = cursor.fetchall()
for column in columns:
    print(column)

# 获取user表的数据
print("\n===== 用户表数据 =====")
cursor.execute('SELECT * FROM "user" LIMIT 5')
users = cursor.fetchall()
for user in users:
    print(user)

# 获取skill表的结构
print("\n===== 技能表结构 =====")
cursor.execute('PRAGMA table_info(skill)')
columns = cursor.fetchall()
for column in columns:
    print(column)

# 获取skill表的数据
print("\n===== 技能表数据 =====")
cursor.execute('SELECT * FROM skill LIMIT 5')
skills = cursor.fetchall()
for skill in skills:
    print(skill)

# 获取article表的结构
print("\n===== 文章表结构 =====")
cursor.execute('PRAGMA table_info(article)')
columns = cursor.fetchall()
for column in columns:
    print(column)

# 获取article表的数据
print("\n===== 文章表数据 =====")
cursor.execute('SELECT * FROM article LIMIT 5')
articles = cursor.fetchall()
for article in articles:
    print(article)

# 获取关联表信息
print("\n===== 用户-技能关联表 =====")
cursor.execute('SELECT * FROM user_skill LIMIT 5')
user_skills = cursor.fetchall()
for user_skill in user_skills:
    print(user_skill)

print("\n===== 文章-技能关联表 =====")
cursor.execute('SELECT * FROM article_skill LIMIT 5')
article_skills = cursor.fetchall()
for article_skill in article_skills:
    print(article_skill)

conn.close()